import request from '@renderer/utils/request'

// 登录接口参数类型
export interface LoginParams {
  username: string
  password: string
}

// 登录响应数据类型
export interface LoginResponse {
  token: string
  refreshToken: string
  user: {
    id: string
    name: string
    userType: 'super_admin' | 'manager' | 'worker'
    avatar: string
    permissions: string[]
    shopId?: string
    shopName?: string
    workerId?: string
    managerId?: string
  }
  redirectPath: string
}

// Token刷新参数类型
export interface RefreshTokenParams {
  refreshToken: string
}

// Token刷新响应类型
export interface RefreshTokenResponse {
  token: string
  refreshToken?: string
  expiresIn: number
}

// 用户信息响应类型
export interface UserProfileResponse {
  user: {
    id: string
    name: string
    userType: 'super_admin' | 'manager' | 'worker'
    avatar: string
    loginTime: string
    onlineDuration: number
    shopId?: string
    shopName?: string
    workerId?: string
    workerStatus?: string
  }
}

// 统一登录接口
export function login(data: LoginParams) {
  return request({
    url: '/auth/login',
    method: 'post',
    data
  })
}

// Token刷新接口
export function refreshToken(data: RefreshTokenParams) {
  return request({
    url: '/auth/refresh',
    method: 'post',
    data
  })
}

// 获取用户信息接口
export function getUserProfile() {
  return request({
    url: '/auth/profile',
    method: 'get'
  })
}

// 登出接口
export function logout() {
  return request({
    url: '/auth/logout',
    method: 'post'
  })
}

// 验证Token有效性
export function validateToken() {
  return request({
    url: '/auth/validate',
    method: 'get'
  })
}

// 测试连接接口
export function testConnection() {
  return request({
    url: '/api/health',
    method: 'get'
  })
}
